﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace TSCL.Web.article
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(id);
				}
			}
		}
			
	private void ShowInfo(int id)
	{
		TSCL.BLL.article bll=new TSCL.BLL.article();
		TSCL.Model.article model=bll.GetModel(id);
		this.lblid.Text=model.id.ToString();
		this.txtmenuid.Text=model.menuid.ToString();
		this.txtarticletitle.Text=model.articletitle;
		this.txtarticleceater.Text=model.articleceater;
		this.txtarticlecontent.Text=model.articlecontent;
		this.txtpubtime.Text=model.pubtime.ToString();
		this.txtispub.Text=model.ispub.ToString();
		this.txtremarks.Text=model.remarks;
		this.txttagid.Text=model.tagid.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtmenuid.Text))
			{
				strErr+="menuid格式错误！\\n";	
			}
			if(this.txtarticletitle.Text.Trim().Length==0)
			{
				strErr+="articletitle不能为空！\\n";	
			}
			if(this.txtarticleceater.Text.Trim().Length==0)
			{
				strErr+="articleceater不能为空！\\n";	
			}
			if(this.txtarticlecontent.Text.Trim().Length==0)
			{
				strErr+="articlecontent不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtpubtime.Text))
			{
				strErr+="pubtime格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtispub.Text))
			{
				strErr+="ispub格式错误！\\n";	
			}
			if(this.txtremarks.Text.Trim().Length==0)
			{
				strErr+="remarks不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txttagid.Text))
			{
				strErr+="tagid格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int id=int.Parse(this.lblid.Text);
			int menuid=int.Parse(this.txtmenuid.Text);
			string articletitle=this.txtarticletitle.Text;
			string articleceater=this.txtarticleceater.Text;
			string articlecontent=this.txtarticlecontent.Text;
			DateTime pubtime=DateTime.Parse(this.txtpubtime.Text);
			int ispub=int.Parse(this.txtispub.Text);
			string remarks=this.txtremarks.Text;
			int tagid=int.Parse(this.txttagid.Text);


			TSCL.Model.article model=new TSCL.Model.article();
			model.id=id;
			model.menuid=menuid;
			model.articletitle=articletitle;
			model.articleceater=articleceater;
			model.articlecontent=articlecontent;
			model.pubtime=pubtime;
			model.ispub=ispub;
			model.remarks=remarks;
			model.tagid=tagid;

			TSCL.BLL.article bll=new TSCL.BLL.article();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
